package com.demo.test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class ThreadPoolDemo {
	public ExecutorService service;
	private static ThreadPoolDemo instance;

	public ThreadPoolDemo() {
		service = Executors.newFixedThreadPool(2);
	}
	
	public static ThreadPoolDemo getInstance() {
		if(instance == null) {
			instance = new ThreadPoolDemo();
		}
		return instance;
	}
	
	public static void main(String[] args) {
		CountDownLatch countDownLatch = new CountDownLatch(2);
		ThreadDemo t0 = new ThreadDemo("第0个测试线程");
		ThreadDemo1 t1 = new ThreadDemo1("第1个测试线程");
		ThreadDemo2 t2 = new ThreadDemo2("第2个测试线程", countDownLatch);
		ThreadDemo3 t3 = new ThreadDemo3("第3个测试线程", countDownLatch);
		ThreadDemo4 t4 = new ThreadDemo4("第4个测试线程", countDownLatch);
		ThreadDemo4 t5 = new ThreadDemo4("第5个测试线程", countDownLatch);
		ThreadDemo4 t6 = new ThreadDemo4("第6个测试线程", countDownLatch);
		ThreadDemo4 t7 = new ThreadDemo4("第7个测试线程", countDownLatch);
		ThreadDemo4 t8 = new ThreadDemo4("第8个测试线程", countDownLatch);
		ThreadDemo4 t9 = new ThreadDemo4("第9个测试线程", countDownLatch);
		ThreadDemo4 t10 = new ThreadDemo4("第10个测试线程", countDownLatch);
		ThreadDemo4 t11 = new ThreadDemo4("第11个测试线程", countDownLatch);
		ThreadDemo4 t12 = new ThreadDemo4("第12个测试线程", countDownLatch);
		ThreadDemo4 t13 = new ThreadDemo4("第13个测试线程", countDownLatch);
		ThreadDemo4 t14 = new ThreadDemo4("第14个测试线程", countDownLatch);
		ThreadDemo4 t15 = new ThreadDemo4("第15个测试线程", countDownLatch);
		ThreadDemo4 t16 = new ThreadDemo4("第16个测试线程", countDownLatch);
		ThreadDemo4 t17 = new ThreadDemo4("第17个测试线程", countDownLatch);
		ThreadDemo4 t18 = new ThreadDemo4("第18个测试线程", countDownLatch);
		ThreadDemo4 t19 = new ThreadDemo4("第19个测试线程", countDownLatch);
		ThreadDemo4 t20 = new ThreadDemo4("第20个测试线程", countDownLatch);
		ThreadPoolDemo threadPoolDemo = ThreadPoolDemo.getInstance();
		threadPoolDemo.service.execute(t3);
		threadPoolDemo.service.execute(t0);
		threadPoolDemo.service.execute(t1);
		threadPoolDemo.service.execute(t4);
		threadPoolDemo.service.execute(t2);
		threadPoolDemo.service.execute(t5);
		threadPoolDemo.service.execute(t6);
		threadPoolDemo.service.execute(t7);
		threadPoolDemo.service.execute(t8);
		threadPoolDemo.service.execute(t9);
		threadPoolDemo.service.execute(t10);
		threadPoolDemo.service.execute(t11);
		threadPoolDemo.service.execute(t12);
		threadPoolDemo.service.execute(t13);
		threadPoolDemo.service.execute(t14);
		threadPoolDemo.service.execute(t15);
		threadPoolDemo.service.execute(t16);
		threadPoolDemo.service.execute(t17);
		threadPoolDemo.service.execute(t18);
		threadPoolDemo.service.execute(t19);
		
		threadPoolDemo.service.execute(t20);
		
		threadPoolDemo.service.shutdown();
	}

}
